package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.ApplyConfirmationTbl;
import com.amigo.online.provider.manager.model.entity.ApplyDetailTbl;
import com.amigo.online.provider.manager.model.entity.ApplyTbl;
import com.amigo.online.provider.manager.service.ApplyConfirmationService;
import com.amigo.online.provider.manager.service.ApplyDetailTblService;
import com.amigo.online.provider.manager.service.ApplyTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/applytbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ApplyTblController extends BaseController {

    @Resource
    private ApplyTblService applytblservice;

    @Resource
    private ApplyDetailTblService applyDetailTblService;
    @Resource
    private ApplyConfirmationService applyConfirmationService;

    @PostMapping(value = "/getApplytblList")
    public ResponseEntity<Response> getApplytblList(@RequestBody ApplyTbl applytbl) {
        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(applytbl.getPageNo(), 10);
        List<ApplyTbl> applylist = applytblservice.select(applytbl);
        result.put("applylist", applylist);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    @PostMapping(value = "/getApplyDetailTbl")
    public ResponseEntity<Response> getApplyDetailTbl(@RequestBody ApplyDetailTbl applyDetailTbl) {
        JSONObject result = new JSONObject();
        List<ApplyDetailTbl> ApplyDetaillist = applyDetailTblService.select(applyDetailTbl);
        result.put("ApplyDetaillist", ApplyDetaillist);

        return success(result);
    }

    /**
     * 修改冻结数量
     * 审核广告
     *
     * @param applytbl
     * @return
     */
    @PutMapping(value = "/updateSourceTbl")
    public ResponseEntity<Response> updateSourceTbl(@RequestBody ApplyConfirmationTbl applytbl) {
        int ii = applyConfirmationService.update(applytbl);
        if (ii <= 0) {
            return success(false);
        } else {
            return success(true);
        }

    }

}
